//Virtual Machine: main.c
// 5.4.08

#include <stdio.h>
#include <stdlib.h>
#include "vm.h"

int main(int argc, char *argv[])
{
	if (argc == 2)
	{
		// open file
		FILE *fp = fopen(argv[1], "r");

		// check for valid file
		if(fp == NULL)
		{
		 	fprintf(stderr, "Error: Must use a valid file\n");
		 	exit(0);
		 }
		
		struct vm_State *vm;
		
		vm = new_vm();

        vm_make(fp, stderr, vm); // calls the lexer to create an array of struct commands
		
        vm_execute(stdin, stdout, stderr, vm); // if statement tests each command in the array and calls the appropriate function

        vm_delete(vm); //  frees the array of structs and any variables
	}
	
	else // if one file is not in command line argument
	{
		fprintf(stderr, "Error: Must run program with one file in command line\n");
	}

}
